package rsj.interceptor;

import java.util.*;

/**
 * 菜单-API映射关系
 *
 * @author yuanqinglong
 * @since 2021/5/28 9:13
 */
public enum MenuAuthMapping {

    /**
     * 菜单-api
     * size: 33
     */
    //PUBLIC_PAGE("M01", "公共页面", "/homeIndex", "/api/rsj/prod/show,/api/rsj/prod/apply,/api/rsj/sys/menuListByUser,/api/rsj/sys/userUname"),
    PUBLIC_PAGE("M01", "公共页面", "/homeIndex", "/api/rsj/prod/show,/api/rsj/prod/apply,/api/rsj/sys/menuListByUser,/api/rsj/sys/userinfo"),
    DATA_MARKET("Y001", "数据市场", "/more", "/api/rsj/prod/list/by/org,/api/rsj/prod/collect,/api/rsj/prod/apply"),
    DATA_DETAILS("Y002", "数据详情-接口信息", "/details", "/api/rsj/prod/findId,/api/rsj/prod/updateList"),
    ACCOUNT_MANAGEMENT("Y003", "账户管理", "/userCenter/account", "/api/rsj/operative/orguser,/api/rsj/sys/logList,/api/rsj/sys/updatePassword"),
    MY_DATA("Y004", "我的数据", "/userCenter/data", "/api/rsj/prod/satisfyList,/api/rsj/prod/probationList,/api/rsj/prod/collectList"),
    MY_BILL("Y005", "我的账单", "/userCenter/bill", "/api/rsj/operative/prodList,/api/rsj/operative/bilList,/api/rsj/operative/bilConfirm"),
    //RECHARGE_RECORD("Y006", "充值记录", "/userCenter/recharge", "/api/rsj/prod/rechargeList"),
    RECHARGE_RECORD("Y006", "充值记录", "/userCenter/recharge", "/api/rsj/my/rechargeList"),
//    INSTITUTIONAL_MANAGEMENT("Y007", "机构管理", "/operate/mechanism", "/api/rsj/operative/orgList"),
//    KEY_AGENCY_MANAGEMENT("Y008", "秘钥机构管理", "/operate/keysAdmin", "/api/rsj/org/authInfo"),
//    RECHARGE_MAINTENANCE("Y009", "充值维护", "/operate/adminRecharge", "/api/rsj/operative/orgId,/api/rsj/prod/rechargeList,/api/rsj/prod/class,/api/rsj/prod/rechargeInsert,/api/rsj/operative/orgpstatus"),
    RECHARGE_MAINTENANCE("Y009", "账务配置", "/operate/adminRecharge", "/api/rsj/contract/add,/api/rsj/product/configured/get"),
//    NEW_INSTITUTION("Y010", "新建机构", "/operate/add", "/api/rsj/operative/update,/api/rsj/operative/insert"),
//    PRODUCT_MANAGEMENT("Y011", "产品管理", "/operate/management", "/api/rsj/prod/list"),
    PRODUCT_MANAGEMENT("Y011", "接口信息", "/operate/management", "/api/rsj/prod/list"),
    ADD_PRODUCT("Y012", "添加产品", "/operate/addProject", "/api/rsj/prod/findId,/api/rsj/prod/update,/api/rsj/prod/insert"),
    EDIT_PRODUCT("Y013", "编辑产品", "/operate/addProject", "/api/rsj/prod/findId,/api/rsj/prod/update,/api/rsj/prod/insert"),
    CHANGE_PASSWORD_1("Y014", "修改密码", "/operate/password", "/api/rsj/sys/updatePassword"),
    USER_MANAGEMENT("Y015", "用户管理", "/admin/userAdmin", "/api/rsj/sys/userlist,/api/rsj/sys/userDel"),
    NEW_USER("Y016", "新建用户", "/admin/userAdmin/edit", "/api/rsj/sys/roleAll,/api/rsj/sys/webItem,/api/rsj/sys/userUname,/api/rsj/sys/userUpdate,/api/rsj/sys/userInsert"),
    ROLE_MANAGEMENT("Y017", "角色管理", "/admin/roleAdmin", "/api/rsj/sys/roleList"),
    NEW_ROLE("Y018", "新增角色", "/admin/roleAdmin/newRole", "/api/rsj/sys/roleById,/api/rsj/sys/menuAuth,/api/rsj/sys/roleInsert,/api/rsj/sys/roleUpdate"),
    CHANGE_PASSWORD_2("Y019", "修改密码", "/admin/changePas", "/api/rsj/sys/updatePassword"),
//    ONLINE_DATA_TEST("Y020", "线上数据测试", "/operate/infctest", "/api/rsj/add/data/select/org,/api/rsj/product/test/category,/file/commonFileUpload,/api/rsj/data/testQuery,/api/rsj/query/org/key"),
    ONLINE_DATA_TEST("Y020", "线上数据测试", "/operate/infctest", "/api/rsj/customer/select/list,/api/rsj/auth/list/customer,/api/rsj/product/test/category,/file/commonFileUpload,/api/rsj/data/testQuery,/api/rsj/query/org/key"),
    REPORT_MANAGEMENT("Y021", "测试结果查看", "/operate/rptadmin", "/api/rsj/rep/loglist,/api/rsj/rep/exportTestResult"),
    RESULTS_DOWNLOAD("Y022", "结果下载", "/operate/resdown", "/api/rsj/data/get/upload/result,/api/rsj/data/get/file/info,/api/rsj/download/oper/log"),
//    PERSONAL_CENTER("Y023", "个人中心", "/operate/oprCenter", "/api/rsj/sys/userinfo"),
//    CUSTOMER_USAGE_REPORT("Y024", "客户使用情况报表", "/operate/usage", "/api/rsj/org/test/usage/report,/api/rsj/start/statistic,/api/rsj/org/produce/usage/report,/api/rsj/org/test/current/table/export,/api/rsj/org/test/export/all,/api/rsj/org/produce/current/table/export,/api/rsj/org/produce/export/all,/api/rsj/org/produce/download/detail,/api/rsj/org/test/download/detail"),
//    TEST_DATA_IMPORT("Y025", "测试数据导入", "/operate/importData", "/api/rsj/query/import/failed/data,/file/commonFileUpload,/api/rsj/import/test/data,/api/rsj/upload/again"),
//    PRODUCT_USAGE_REPORT("Y026", "产品使用情况报表", "/operate/proUsage", "/api/rsj/product/test/usage/report,/api/rsj/product/produce/usage/report,/api/rsj/product/offline/usage/report,/api/rsj/product/test/current/table/export,/api/rsj/product/test/export/all,/api/rsj/product/test/download/detail,/api/rsj/product/produce/current/table/export,/api/rsj/product/produce/export/all,/api/rsj/product/produce/download/detail,/api/rsj/product/offline/current/table/export"),
    OFFLINE_TEST_REPORT("Y027", "线下测试报表", "/operate/offlineTest", "/api/rsj/my/company/test/report,/api/rsj/supplier/test/report,/api/rsj/export/my/company/test/report,/api/rsj/export/supplier/test/report"),
//    OFFLINE_DATA_ENTRY("Y028", "线下数据录入", "/operate/offlineDataEntry", "/api/rsj/add/data/select/org,/api/rsj/add/data/select/prod,/api/rsj/add/test/data"),
    OFFLINE_DATA_ENTRY("Y028", "线下数据录入", "/operate/offlineDataEntry", "/api/rsj/auth/list/customer,/api/rsj/customer/select/list,/api/rsj/add/data/select/prod,/api/rsj/add/test/data"),
    APPLICATION_TIMETASK("Y029", "定时任务监控", "/operate/application/timeTask", "/api/rsj/monitor/job/info"),
    CUSTOMER_lIST("Y031", "客户列表", "/operate/custList", "/api/rsj/customer/list"),
    CUSTOMER_ADD("Y032", "添加/编辑客户", "/operate/add", "/api/rsj/customer/update,/api/rsj/customer/get,/api/rsj/customer/add"),
    ACCOUNT_LIST("Y033", "账号列表", "/operate/mechanism", "/api/rsj/account/status/update,/api/rsj/account/list"),
    ACCOUNT_ADD("Y034", "添加账号", "/operate/addOrg", "/api/rsj/account/add,/api/rsj/product/all,/api/rsj/customer/select/list"),
    ACCOUNT_PERMISSION("Y035", "权限配置", "/operate/updOrg", "/api/rsj/org/ip/update,/api/rsj/account/product/update,/api/rsj/user/password/update,/api/rsj/account/get,/api/rsj/product/delete/check,/api/rsj/customer/select/list,/api/rsj/product/all"),
    FINANCE_LIST("Y036", "账务列表", "/operate/accountList", "/api/rsj/finance/list"),
    ORDER_LIST("Y037", "批次列表", "/operate/orderList", "/api/rsj/contract/status/update,/api/rsj/contract/list"),
    REPORT_ANALYZE("Y040", "报表分析", "/operate/report", "/api/rsj/report/account/list,/api/rsj/report/account/download/log,/api/rsj/report/account/detail/list,/api/rsj/report/account/product/list,/api/rsj/report/account/product/download/log,/api/rsj/report/account/product/detail/list,/api/rsj/report/customer/list,/api/rsj/report/customer/download/log,/api/rsj/report/customer/detail/list,/api/rsj/report/customer/product/list,/api/rsj/report/customer/product/download/log,/api/rsj/report/customer/product/detail/list,/api/rsj/report/product/list,/api/rsj/report/product/download/log,/api/rsj/report/product/detail/list,/api/rsj/report/product/category/list,/api/rsj/report/product/category/download/log,/api/rsj/report/product/category/detail/list,/api/rsj/report/account/detail/export,/api/rsj/report/account/product/detail/export,/api/rsj/report/customer/detail/export,/api/rsj/report/customer/product/detail/export,/api/rsj/report/product/detail/export,/api/rsj/report/account/export,/api/rsj/report/account/product/export,/api/rsj/report/customer/export,/api/rsj/report/customer/product/export,/api/rsj/report/product/export,/api/rsj/report/product/category/export,/api/rsj/report/product/category/detail/export"),
    PERSON_INFO("Y041", "个人信息", "/operate/oprCenter", "/api/rsj/sys/userinfo"),
    PERSON_EXPORT("Y042", "我的导出", "/operate/myExport", "/api/rsj/report/my/export/list"),
    REMIND_INFO("Y044", "预警信息", "/operate/warning", "/api/rsj/sys/userlist,/api/rsj/remind/add,/api/rsj/remind/get,/api/rsj/remind/log,/api/rsj/remind/update"),

    /**
     * M02菜单的页面地址和 "Y003-账户管理" 相同 api一样
     */
    PERSONAL_CENTER_M02("M02", "个人中心", "/userCenter/account", "/api/rsj/operative/orguser,/api/rsj/sys/logList,/api/rsj/sys/updatePassword"),
    /**
     * 运营工作台的页面地址和 "Y007-机构管理" 相同 api一样
     */
    OPERATION_WORKBENCH("M03", "运营工作台", "/operate/mechanism", "/api/rsj/operative/orgList"),
    /**
     * 系统管理员的页面地址和 "Y015-用户管理" 相同 api一样
     */
    SYSTEM_ADMINISTRATOR("M04", "系统管理员", "/admin/userAdmin", "/api/rsj/sys/userlist,/api/rsj/sys/userDel"),
    /**
     * 数据库中数据测试没有menu_url  子菜单"Y020-线上数据测试" 有对应api
     */
    DATA_TEST("M05", "数据测试", "null", ""),
    /**
     * 数据库中应用运维没有menu_url
     */
    APPLICATION("M06", "应用运维", "null", "");

    private final String menuId;

    private final String menuName;

    private final String menuPath;

    private final String apiPath;

    MenuAuthMapping(String menuId, String menuName, String menuPath, String apiPath) {
        this.menuId = menuId;
        this.menuName = menuName;
        this.menuPath = menuPath;
        this.apiPath = apiPath;
    }

    /**
     * 保存菜单ID 和 此菜单对应的API集合
     */
    private static final Map<String, Set<String>> MENU_API_MAPPINGS = new HashMap(128);


    static {
        for (MenuAuthMapping menuAuthMapping : MenuAuthMapping.values()) {
            String[] apis = menuAuthMapping.apiPath.split(",");
            Set<String> apiSet = new HashSet<>(Arrays.asList(apis));
            MENU_API_MAPPINGS.put(menuAuthMapping.menuId, apiSet);
        }
    }


    /**
     * 获取菜单
     *
     * @param menuId menuId
     * @return {@link Set<String>}
     */
    public static Set<String> getMenuById(String menuId) {
        return MENU_API_MAPPINGS.getOrDefault(menuId, new HashSet<>());
    }


}
